home *** CD-ROM | disk | FTP | other *** search
/ Varios Español / Varios Español.iso / DBASE5 / CUA_SAMP.ZIP / FNAME.PRG < prev    next >
Text File  |  1994-10-12  |  4KB  |  95 lines

  1.  
  2. *.............................................................................
  3. *
  4. *   Program Name: FNAME.PRG           Copyright: Borland International
  5. *   Date Created:  7 Jul 94            Language: dBASE 5.0
  6. *   Time Created: 14:58:53               Author: Borland dBASE R&D
  7. *   /brief/library.src
  8. *.............................................................................
  9.  
  10. *............................................................................
  11. * Function Name:    FName
  12. * Parameters:       string (filename), numeric (function code)
  13. * Ext Memvars:      None
  14. * Return Value:     string or logical
  15. * Description:      Function to check various aspects of a given filename.
  16. *                   The first parameter must be a filename, with or without
  17. *                   the path.  Not passing the first parameter, or passing
  18. *                   a non-character value, returns a NULL string.
  19. *                   The second parameter, if given, is a numeric and has
  20. *                   the following meanings:
  21. *                   0: returns the drive, path and full name of the file
  22. *                   1: returns the drive and path of the file
  23. *                   2: returns the file name (no extension)
  24. *                   3: returns the file extension
  25. *                   4: returns the file name and extension
  26. *                   5: returns .T. if the filename is a valid DOS filename,
  27. *                      otherwise returns .F.
  28. *                   Passing no second parameter, or a non-numeric, is the
  29. *                   same as passing 0.
  30. *                   Passing a number > 5 or < 0 for the second parameter
  31. *                   will return a NULL string.
  32. *
  33. * Examples:         ? FNAME("C:\DBASE\DBASE.EXE", 0)
  34. *                   C:\DBASE\DBASE.EXE
  35. *                   ? FNAME("C:\DBASE\DBASE.EXE", 1)
  36. *                   C:\DBASE\
  37. *                   ? FNAME("C:\DBASE\DBASE.EXE", 2)
  38. *                   DBASE
  39. *                   ? FNAME("C:\DBASE\DBASE.EXE", 3)
  40. *                   EXE
  41. *                   ? FNAME("C:\DBASE\DBASE.EXE", 4)
  42. *                   DBASE.EXE
  43. *                   ? FNAME("C:\DBASE\DBASE.EXE", 5)    && Valid DOS filename
  44. *                   .T.
  45. *                   ? FNAME("C:\DB..ASE\DB ASE.EXE", 5) && Bad DOS filename
  46. *                   .F.
  47. *
  48. *............................................................................
  49. FUNCTION FName
  50. PARAMETERS cFileName, nParam
  51.     PRIVATE cRet, nFlag, nVoid
  52.  
  53.     #include "TALKOFF.HDB"
  54.  
  55.     cRet  = ""          && function return value
  56.     nFlag = m->nParam   && copy of second parameter
  57.     nVoid = 0           && unused value to pass to ValFile
  58.  
  59.     IF TYPE("m->cFileName") = "C"
  60.         IF .NOT. ISBLANK(m->cFileName)
  61.             IF (TYPE("m->nFlag") # "N") .AND. (TYPE("m->nFlag") # "F")
  62.                 nFlag = 0
  63.             ENDIF
  64.  
  65.             nFlag = INT(m->nFlag)
  66.  
  67.             IF (m->nFlag >= 0) .AND. (m->nFlag <= 5)
  68.                 DO CASE
  69.                     CASE m->nFlag = 0
  70.                         cRet = FILEDRV(m->cFileName) + ":";
  71.                                + FILEPATH(m->cFileName);
  72.                                + FILEROOT(m->cFileName) + ".";
  73.                                + FILETYPE(m->cFileName)
  74.                     CASE m->nFlag = 1
  75.                         cRet = FILEDRV(m->cFileName) + ":";
  76.                                + FILEPATH(m->cFileName)
  77.                     CASE m->nFlag = 2
  78.                         cRet = FILEROOT(m->cFileName)
  79.                     CASE m->nFlag = 3
  80.                         cRet = FILETYPE(m->cFileName)
  81.                     CASE m->nFlag = 4
  82.                         cRet = FILEROOT(m->cFileName) + ".";
  83.                                + FILETYPE(m->cFileName)
  84.                     CASE m->nFlag = 5
  85.                         cRet = VALFILE(m->cFileName, m->nVoid)
  86.                 ENDCASE
  87.             ENDIF
  88.         ENDIF
  89.     ENDIF
  90.  
  91.     #include "TALKON.HDB"
  92.  
  93. RETURN m->cRet
  94.  
  95.